package com.lagou.edu.pojo;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName: Request
 * @Auther: Jerry
 * @Date: 2020/7/30 23:43
 * @Desctiption: Request对象
 * @Version: 1.0
 */
public class Request {

    private String method;// 请求方法
    private String uri;// 请求路径
    private InputStream inputStream;// 输入流

    public Request() {
    }

    /**
     * 根据输入流构建Request对象
     */
    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;
        int count = 0;
        while (count == 0) {
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);
        String requestHeaders = new String(bytes);
        String[] headers = requestHeaders.split("\r\n");
        System.out.println("=====>>> headers：" + headers[0]);
        String[] firstLineStrs = headers[0].split(" ");
        this.method = firstLineStrs[0];
        this.uri = firstLineStrs[1];
        System.out.println("=====>>> method：" + method);
        System.out.println("=====>>> uri：" + uri);

    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }
}
